﻿FXFormsDialog = function () {
    var m_alertdivhtml = "<div id='dlg_alert' title='Alert' class='fc-dlg fc_dlgpad'><p id='fmAlertMessageBody' ></p><div class=' fr ' id='alertbtndiv' ><button type='button'' class='button orange fc-okbtn' id='btnalert' onclick='g_AlertCallback();' text='OK'></button></div><div class='clear'></div></div>";
    var m_confirmdivhtml = "<div id='dlg_confirm' title='Confirm' class='fc-dlg fc_dlgpad'><p id='fmConfirmMessageBody' > </p><div class='  fr ' id='confirmbtndiv'>  <button type='button' class='button orange fc-okbtn'  onclick='g_ConfirmOKCallback(g_ConfirmOkData)' id='btok' text='OK'></button><button type='button' class='button blue fc-cancelbtn'  onclick='g_ConfirmCancelCallback(g_ConfirmCancelData);' id='btncancel' text='Cancel'></button> </div><div class='clear'></div></div>";
    //var m_loadingdivhtml = "<div><div ><img src='../images/icons/loading.gif' id='imgloading' alt='' /> </div><div class='clear'></div></div>";
    var m_alertDlg = null;
    var m_confirmDlg = null;
    //var m_loadingDlg = null;
    var m_title = "";           //title
    var m_msg = "";         //msg
    var m_show = "";
    var m_hide = ""; 
    var m_btns = null;      //buttons 
    this.m_alertDiv = $(m_alertdivhtml);
    this.m_comfirmDiv = $(m_confirmdivhtml);
    //this.m_loadingDiv = $(m_loadingdivhtml);
    var m_alertBeforeClose = null;
    this.set_Title = function (val) {
        this.m_title = val;
    }
    this.get_Title = function () {
        return this.m_title;
    }
    this.set_Msg = function (val) {
        this.m_msg = val;
    }
    this.get_Msg = function () {
        return this.m_msg;
    }
    this.set_Show = function (val) {
        this.m_show = val;
    }
    this.get_Show = function () {
        return this.m_show;
    }
    this.set_Hide = function (val) {
        this.m_hide = val;
    }
    this.get_Hide = function () {
        return this.m_hide;
    }

    this.set_AlertMsg = function (msg) {

        this.m_alertDiv.children().filter("p").html(msg);
    }
    /*
    this.showloading = function () {
        if (this.m_loadingDlg == null) {
            this.m_loadingDlg = this.m_loadingDiv.dialog({
                autoOpen: false,
                position: 'center',
                modal: true,
                height: 50,
                width:30,
               // closeOnEscape: false,
                title: this.get_Title(),
                dialogClass:'fmloading',
                closeText: ''
            });
        }
        this.m_loadingDlg.dialog("option", "position", 'center');
     //   this.m_loadingDlg.dialog("option", "closeOnEscape", false);
        this.m_loadingDlg.dialog('open');
    }

    this.hideloading = function () {
        if (this.m_loadingDlg != null)
            this.m_loadingDlg.dialog('close');
    }
    */
    this.emptyfunc = function() {
    }


    this.alert = function (title, msg, btntitle, callback,beforecall,width) {
        if (this.m_alertDlg == null) {
            this.m_alertDlg = this.m_alertDiv.dialog({
                autoOpen: false,
                /* show: "blind", 
                hide: "explode", */
                width: 400,
                minHeight: 38,
                position: 'center',
                modal: true,
                title: this.get_Title(),
                closeText: ''
            });
        }
        if (callback != null)
            SetAlertCallBack(callback);
        else {
            ReSetAlertCallBack();
        }

        if(beforecall != null)
            this.m_alertDlg.bind("dialogbeforeclose", beforecall);
        else
            this.m_alertDlg.bind("dialogbeforeclose", this.emptyfunc);

        this.set_Msg(msg);
        this.set_Title(title);
        // this.m_alertDlg.dialog( "option", "show",this.get_Show());
        this.m_alertDlg.dialog("option", "title", this.get_Title());
        // this.m_alertDlg.dialog( "option", "hide", this.get_Hide());
        this.m_alertDlg.dialog("option", "position", 'center');
        if(width == null)
            this.m_alertDlg.dialog("option", "width", 300);
        else
            this.m_alertDlg.dialog("option", "width", width);
        this.m_alertDiv.children().filter("p").html(this.get_Msg()); //custom msg
        if (btntitle == null)
            btntitle = "OK";
        this.m_alertDiv.children('#alertbtndiv').children("#btnalert").text(btntitle);
        	
        this.m_alertDlg.dialog('open');
    }


    this.confirm = function (title, msg, okcallback, cancelcallback, okcallbackData, cancelcallbackData, oktitle, canceltitle, bSetLeftRightPadding_Ok, bSetLeftRightPadding_Cancel) {
        if (this.m_confirmDlg == null) {
            this.m_confirmDlg = this.m_comfirmDiv.dialog({
                autoOpen: false,
                /*show: "blind", 
                hide: "explode", */
                position: 'center',
                minHeight: 38,
                modal: true,
                title: this.get_Title(),
                closeText: ''
            });
        }
        if (okcallback != null)
            SetConfirmOkCallBack(okcallback);
        else {
            ReSetConfirmOkCallBack();
        }
        if (cancelcallback != null)
            SetConfirmCancelCallBack(cancelcallback);
        else {
            ReSetConfirmCancelCallBack();
        }
        if (okcallbackData != null)
        //    alert(okcallbackData);
            SetOkCallBackData(okcallbackData);
        else
            ReSetOkCallBackData();
        if (cancelcallbackData != null)
            SetCancelCallBackData(cancelcallbackData);
        else
            ReSetCancelCallBackData();
        this.set_Msg(msg);
        this.set_Title(title);
        if (oktitle == null)
            oktitle = "OK";
        if (canceltitle == null)
            canceltitle = "Cancel";
        //this.m_confirmDlg.dialog( "option", "show",this.get_Show());
        this.m_confirmDlg.dialog("option", "title", this.get_Title());
        //this.m_confirmDlg.dialog( "option", "hide", this.get_Hide());
        this.m_confirmDlg.dialog("option", "position", 'center');
        this.m_comfirmDiv.children().filter("p").html(this.get_Msg()); //custom msg
        this.m_comfirmDiv.children('#confirmbtndiv').children("#btok").text(oktitle);
        this.m_comfirmDiv.children('#confirmbtndiv').children("#btncancel").text(canceltitle);
        this.m_confirmDlg.dialog('open');
        if (bSetLeftRightPadding_Ok) {
            $("#btok").css("padding", "0px 10px");
        }
        if (bSetLeftRightPadding_Cancel) {
            $("#btncancel").css("padding", "0px 10px");
        }
    }

    this.endalert = function () {
        if (this.m_alertDlg != null)
            this.m_alertDlg.dialog('close');
    }

    this.endconfirm = function () {
        if (this.m_confirmDlg != null)
            this.m_confirmDlg.dialog('close');

        $("#btok").css("padding", "0px 0px");
        $("#btncancel").css("padding", "0px 0px");
    }

} 

        var  g_DlgHelper = null; 
        var  g_ConfirmOkData = null;
        var  g_ConfirmCancelData;
        var g_AlertCallback = function () {
                g_DlgHelper.endalert();
         };

        var g_ConfirmOKCallback = function () {
                g_DlgHelper.endconfirm();
         };

        var g_ConfirmCancelCallback = function () {
                g_DlgHelper.endconfirm();
         };

        function InitDlgHelper() {
            if(g_DlgHelper == null){
                g_DlgHelper = new FXFormsDialog(); 
            }   
         }

         function ReSetAlertCallBack()
         {
            g_AlertCallback = function () {
                g_DlgHelper.endalert();
             };
         }

         function ReSetConfirmOkCallBack()
         {
             g_ConfirmOKCallback = function () {
                g_DlgHelper.endconfirm();
             };
         }

         function ReSetConfirmCancelCallBack()
         {
             g_ConfirmCancelCallback = function () {
                g_DlgHelper.endconfirm();
             };
         }

         function ReSetOkCallBackData()
         {
            g_ConfirmOkData = null;
         }
       
         function SetOkCallBackData(data)
         {
           // g_ConfirmOkData = data;
            g_ConfirmOkData = data;
         }

         function ReSetCancelCallBackData()
         {
            g_ConfirmCancelData = null;
         }

         function SetCancelCallBackData(data)
         {
            g_ConfirmCancelData = data;
         }

         function SetAlertCallBack(callback)
         {
            g_AlertCallback = callback;
         }

         function SetConfirmOkCallBack(callback)
         {
            g_ConfirmOKCallback = callback;
         }

         function SetConfirmCancelCallBack(callback)
         {
            g_ConfirmCancelCallback = callback;
         }
  